<template>
	<view class="backgroundhead">
		<view class="fonthead">
			<text>登录</text>
		</view>
		<view class="box">

			<view class="logo">
				<img src="../../static/logo.png" class="logo">
			</view>
        
			<view class="input">
				<uni-easyinput v-model="user.phone" placeholder="请输入手机号" maxlength=11></uni-easyinput>
			</view>
			<view class="input">
				<uni-easyinput type="password" v-model="user.password" placeholder="请输入密码"></uni-easyinput>
			</view>
			<view>
			<u--text @click="zc" text="无账号,请注册"></u--text>
			</view>
			<view class="wjma">
			<u--text @click="wj" text="忘记密码"></u--text>
			</view>
			<view class="buttonexit">
				<button class="button-yuanjiao" hover-class="bg-click" @click="log(user)">登录</button>
			</view>
			<view class="buttonexit">
				<button class="button-yuanjiao2" hover-class="bg-click" @click="">取消</button>
			</view>
		</view>
    
	</view>
</template>

<script>
		import request from '../../request.js'
	export default {
		data() {
			return {
				user: {
					phone: '',
					password: '',
					userid: 0
				}
			}
		},
		onLoad() {

		},
		methods: {
			zc(){
									uni.navigateTo({
										url: '/pages/login/zhuce'
									})
			},
			wj(){
				uni.navigateTo({
					url: '/pages/login/uppwd'
				})
			},

			log(user) {
				console.log(user)
				request({
					url: '/systemuser/user/getUserLogin',
					method: 'GET',
					data: {
						phone: user.phone,
						password: user.password
					},
					dataType: 'json',
					success: (res) => {
						console.log(res.data.data)
						this.userVo = res.data.data.userVo;
						//let id = res.data.data.userVo.userId + ""
						// let sign = res.data.data.UserSig
						// uni.$TUIKit.login({
						// 		userID: id,
						// 		userSig: sign
						// 	})
						// 	.then(function(imResponse) {

						// 		console.log(imResponse.data); // 登录成功

						// 	})
						// 	.catch(function(imError) {
						// 		console.warn('login error:', imError); // 登录失败的相关信息
						// 	})
						// console.log(this.userVo)
						if (this.userVo == null) {
							uni.showLoading({
								title: '手机号或密码出错！请重新输入'
							})
							setTimeout(() => {
								uni.hideLoading()
								console.log(val)
								this.value = val
								// 关闭窗口后，恢复默认内容
								this.$refs.inputDialog.close()
							}, 1000)

						} else {
							localStorage.setItem("userId",JSON.stringify(res.data.data.userVo.userId))
							localStorage.setItem("userInfo",JSON.stringify(res.data.data.userVo))
							console.log(this.userVo.userId)
							// this.userid = this.userVo.userId
							uni.setStorage({
								key: 'userid',
								data: res.data.data.userVo.userId,
								success: (res) => {
									uni.switchTab({
										url: '/pages/index/index'
									})
								}
							})

						}
					},
				})
			}
		}
	}
</script>

<style>
	.wjma{
		position: absolute;
		right: 120rpx;
		top: 780rpx;
	}
	.button-yuanjiao {
		width: 550rpx;
		height: 80rpx;
		display: flex;
		line-height: 50rpx;
		justify-content: center;
		border-radius: 25px;
		// 这里可以改成渐变： 
		background: linear-gradient(to right, #2ECC71, #2ABA66);
		/* background-color: #ED5565; */
		font-size: 17px;
		color: #FFFFFF;
		margin-top: 110px;
		padding: 7px;
		// font-family:STCaiyun;
	}

	.button-yuanjiao2 {
		width: 550rpx;
		height: 80rpx;
		display: flex;
		line-height: 50rpx;
		justify-content: center;
		border-radius: 25px;
		/* // 这里可以改成渐变： 
		background: linear-gradient(to right, #2ECC71, #2ABA66); */
		background-color: #FFFFFF;
		font-size: 17px;
		color: #2ECC71;
		margin-top: 10px;
		padding: 7px;
		border: 1px solid #2ECC71;

	}

	.buttonexit {
		/* margin-top: rpx; */
		/* border: 5px solid #3F536E; */
		/* 	margin-left: 10rpx; */
		float: left;
	}

	.input {
		margin-top: 50rpx;
	}

	.logo {
		width: 415rpx;
		height: 250rpx;
		/* 	border: 1px solid #3F536E; */
		margin: 20rpx auto;
	}

	.box {
		width: 600rpx;
		height: 1000rpx;
		border-radius: 7px;
		border: 1px solid #3F536E;
		padding: 10px;
		margin: 100rpx 50rpx auto;
		box-shadow: darkgrey 3px 3px 3px 3px;
		/* // position: absolute;
		// left: 25rpx; */
		background-color: #FFFFFF;
		float: left;

	}

	.fonthead {
		color: #000;
		font-size: 50rpx;
		margin-top: 100rpx;
		margin-left: 70rpx;
		float: left;
	}

	.backgroundhead {
		/* background-image: url('../img/xia.png'); */
		width: 100%;
		height: 234px;
		// font-family:Microsoft YaHei;

	}

	page {
		background-color: #EBFCF9;
		font-weight: bold;
	}
</style>